home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / filter1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  4.4 KB  |  140 lines

  1. //----------------------------------------------------------------------------
  2. //Borland C++Builder
  3. //Copyright (c) 1987, 1998 Borland International Inc. All Rights Reserved.
  4. //----------------------------------------------------------------------------
  5. //---------------------------------------------------------------------------
  6. #include <vcl.h>
  7. #pragma hdrstop
  8.  
  9. #include "Filter1.h"
  10. #include "DM.h"
  11. #include "CustView.h"
  12.  
  13. //---------------------------------------------------------------------------
  14. #pragma resource "*.dfm"
  15. //---------------------------------------------------------------------------
  16. __fastcall TfmFilterFrm::TfmFilterFrm(TComponent* Owner)
  17.   : TForm(Owner)
  18. {
  19. }
  20. //---------------------------------------------------------------------------
  21. TfmFilterFrm *fmFilterFrm;
  22.  
  23. // Adds current listbox field name to memo.
  24. //
  25. void __fastcall TfmFilterFrm::AddFieldName(TObject *Sender)
  26. {
  27.    if (Memo1->Text != ""){
  28.      Memo1->Text =  Memo1->Text + " " +
  29.                     ListBox1->Items->Strings[ListBox1->ItemIndex];
  30.    }
  31.    else
  32.      Memo1->Text = ListBox1->Items->Strings[ListBox1->ItemIndex];
  33. }
  34.  
  35. // Adds current Filter operator to memo.
  36. //
  37. void __fastcall TfmFilterFrm::ListBox2DblClick(TObject *Sender)
  38. {
  39.    if (Memo1->Text != ""){
  40.      Memo1->Text = Memo1->Text + " " +
  41.                    ListBox2->Items->Strings[ListBox2->ItemIndex];
  42.    }
  43.    else
  44.      Memo1->Text = ListBox2->Items->Strings[ListBox2->ItemIndex];
  45. }
  46.  
  47. void __fastcall TfmFilterFrm::ApplyFilter(TObject *Sender)
  48. {
  49.   TDataSet* data(DM1->CustomerSource->DataSet);
  50.   if (ComboBox1->Text != "") {
  51.     data->Filter = ComboBox1->Text;
  52.     data->Filtered = true;
  53.     fmCustView->Caption = "Customers - Filtered";
  54.   }
  55.   else {
  56.     data->Filter = "";
  57.     data->Filtered = false;
  58.     fmCustView->Caption = "Customers - Unfiltered";
  59.   }
  60. }
  61.  
  62. // Populates ListBox and ComboBox for the form.
  63. //
  64. void __fastcall TfmFilterFrm::FormCreate(TObject *Sender)
  65. {
  66. // Populate the ListBox1 with available fields from the Customer DataSet.
  67.   for (int i = 0; i < DM1->CustomerSource->DataSet->FieldCount; i++)
  68.     ListBox1->Items->Add(DM1->Customer->Fields[i]->FieldName);
  69.   Memo1->Lines->Clear();
  70.  
  71. // These strings could not be added to the ComboBox at design time because to
  72. // do so would have hard wired us for a single country's date format.  The
  73. // following lines will honor Windows 95 and NT's regional settings.
  74.   ComboBox1->Items->Add("LastInvoiceDate >= '" +
  75.                          DateToStr(EncodeDate(94, 9, 30)) + "'");
  76.   ComboBox1->Items->Add("Country = 'US' and LastInvoiceDate > '" +
  77.                          DateToStr(EncodeDate(94, 6, 30)) + "'");
  78. }
  79.  
  80. // Since the Filter property is a TStrings and the Memo field
  81. // is a TMemo, convert the Memo's wrapped text to a string,
  82. // which is then used when the user presses Apply.
  83. //
  84. void __fastcall TfmFilterFrm::Memo1Change(TObject *Sender)
  85. {
  86.   ComboBox1->Text = Memo1->Lines->Strings[0];
  87.   for (int i = 1; i < Memo1->Lines->Count; ++i){
  88.     ComboBox1->Text = ComboBox1->Text + " " + Memo1->Lines->Strings[i];
  89.   }
  90. }
  91.  
  92. // Set the Customer's DataSet Case Sensitive Filter Option.
  93. //
  94. void __fastcall TfmFilterFrm::cbCaseSensitiveClick(TObject *Sender)
  95. {
  96.   TDataSet* data(DM1->CustomerSource->DataSet);
  97.   if (cbCaseSensitive->Checked)
  98.     data->FilterOptions >> foCaseInsensitive;
  99.   else
  100.     data->FilterOptions << foCaseInsensitive;
  101. }
  102.  
  103. // Set the Customer Partial Compare Filter Option.
  104. //
  105. void __fastcall TfmFilterFrm::cbPartialCompareClick(TObject *Sender)
  106. {
  107.   TDataSet* data(DM1->CustomerSource->DataSet);
  108.   if (cbPartialCompare->Checked)
  109.     data->FilterOptions << foNoPartialCompare;
  110.   else
  111.     data->FilterOptions >> foNoPartialCompare;
  112. }
  113.  
  114. // Add User-Entered filters into list box at runtime.
  115. //
  116. void __fastcall TfmFilterFrm::SBtnClearClick(TObject *Sender)
  117. {
  118.   Memo1->Lines->Clear();
  119.   AnsiString st(ComboBox1->Text);
  120.   ComboBox1->Text = "";
  121.   if (ComboBox1->Items->IndexOf(st) == -1)
  122.     ComboBox1->Items->Add(st);
  123. }
  124.  
  125. // Reset the Memo field when the Filter ComboBox changes.
  126. //
  127. void __fastcall TfmFilterFrm::ComboBox1Change(TObject *Sender)
  128. {
  129.   Memo1->Lines->Clear();
  130.   Memo1->Lines->Add(ComboBox1->Text);
  131. }
  132.  
  133. // Close the Filter Form.
  134. //
  135. void __fastcall TfmFilterFrm::SBtnCloseClick(TObject *Sender)
  136. {
  137.   Close();
  138. }
  139. //---------------------------------------------------------------------------
  140.